<?php
/**
 * Created by JetBrains PhpStorm.
 * User: minhsong
 * Date: 1/21/14
 * Time: 12:24 AM
 * To change this template use File | Settings | File Templates.
 */

class channelService {
    private $db = null;
    function __construct(){
        $this->db = Database::GetDataBaseObj();
    }

    public  function getAllChannel(){
        $query = "select * from tbl_channel ORDER BY Title ASC";
        return $this->db->GetManyRows($query);
    }

    public  function getChannelServers($id){
        $query = "select * from tbl_server where ChannelId = ".$id;
        if($id==15){
            $query = $query." ORDER BY Id DESC";
        }
        return $this->db->GetManyRows($query);
    }
    public function channels(){
        $channels = $this::getAllChannel();
        $result = array();
        foreach($channels as &$channel){
            $channel["Servers"] = $this::getChannelServers($channel["Id"]);
            $result[] = $channel;
        }
        return $result;
    }

    public function insertServer($cId,$ServerName,$link){
        $query = "INSERT INTO tbl_server(ChannelId,Name,Link,isLive) VALUES ($cId,'$ServerName','$link',1)";
        return $this->db->Insert($query);
    }
}